package com.jiangxiaofei.citycloud.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jiangxiaofei.citycloud.R;
import com.jiangxiaofei.citycloud.activity.recruit.RecruitFindWorkInfoActivity;
import com.jiangxiaofei.citycloud.bean.JobListBean;
import com.jiangxiaofei.citycloud.constants.StringConstants;
import com.jiangxiaofei.citycloud.event.EventMessage;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * Created by Administrator on 2017/9/12 0012.
 */

public class RetruitWorkListAdapter extends RecyclerView.Adapter<RetruitWorkListAdapter.WorkViewHolder> {
    List<JobListBean> jobList;
    Context mContext;

    public RetruitWorkListAdapter(List<JobListBean> jobList, Context mContext) {
        this.jobList = jobList;
        this.mContext = mContext;
    }

    @Override
    public WorkViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_job_list_layout, parent, false);
        WorkViewHolder holder = new WorkViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(WorkViewHolder holder, final int position) {
        holder.tvTitle.setText(jobList.get(position).getDescription());
        holder.tvTitle.setOnClickListener(view -> {
            Intent intent = new Intent(mContext, RecruitFindWorkInfoActivity.class);
            intent.putExtra(StringConstants.WORKID, jobList.get(position).getId());
            intent.putExtra(StringConstants.USERTYPE, StringConstants.ISLIST);
            mContext.startActivity(intent);
        });
        holder.tvTitle.setOnLongClickListener(v -> {
            EventMessage.DoWorkLongDeleteMsg longDelete = new EventMessage.DoWorkLongDeleteMsg(jobList.get(position).getId());
            EventBus.getDefault().post(longDelete);
            return true;
        });
    }

    @Override
    public int getItemCount() {
        return jobList.size();
    }

    public class WorkViewHolder extends RecyclerView.ViewHolder {
        TextView tvTitle;

        public WorkViewHolder(View itemView) {
            super(itemView);
            tvTitle = itemView.findViewById(R.id.item_tv_title);
        }
    }
}
